# Contributor: Uli Baum <xeji@cat3.de>
# Maintainer: Uli Baum <xeji@cat3.de>
pkgname=innernet
pkgver=1.6.1
pkgrel=0
pkgdesc="A private network system that uses WireGuard under the hood"
url="https://github.com/tonarino/innernet"
# s390x: nix crate fails to build
# loongarch64: blocked by libc crate
arch="all !s390x !loongarch64"
license="MIT"
makedepends="cargo clang-dev sqlite-dev cargo-auditable"
subpackages="
	$pkgname-openrc
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/tonarino/innernet/archive/v$pkgver/innernet-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname-server.initd
	$pkgname-server.confd

	unbundle-sqlite.patch
	"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --release --frozen
}

package() {
	install -Dm 755 -t "$pkgdir"/usr/sbin/ \
		target/release/innernet target/release/innernet-server

	install -Dm 755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm 644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm 755 "$srcdir"/$pkgname-server.initd "$pkgdir"/etc/init.d/$pkgname-server
	install -Dm 644 "$srcdir"/$pkgname-server.confd "$pkgdir"/etc/conf.d/$pkgname-server

	local binary; for binary in innernet innernet-server; do
		install -Dm 644 doc/$binary.completions.bash "$pkgdir"/usr/share/bash-completion/completions/$binary
		install -Dm 644 doc/$binary.completions.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$binary.fish
		install -Dm 644 doc/$binary.completions.zsh "$pkgdir"/usr/share/zsh/site-functions/_$binary
		install -Dm 644 doc/$binary.8.gz -t "$pkgdir"/usr/share/man/man8
	done

	install -Dm 644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
	install -Dm 644 README.md -t "$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
f8d3bb1e269105ade2c9d4f1b778e13e903ef7c01921b5ab5ce1156f568935b9c032909a72e3f67cf46b67fc32101da26225847bde50d07d1b7d111fb8e000ad  innernet-1.6.1.tar.gz
695a58dd6440ad521c6fbc6f9ca2c9277639d9beed081a74d4afece2446c0c9134845371918e7f0dbd9a7d1c28116abfef88f4ab51ef3abad95e64f29c9ab3b8  innernet.initd
e7ae351d75ad099f1694037994fcc4900c87ab91da585181912303b4a76eb802fd253157ce93c10a093d37272f75699a4e944d65187d020f93cd2bb33f4d7ec2  innernet.confd
1d1ada2d24215d22f230d551634fe9fa464ce24430bfea3ea46b95b716e56f213d78b7ee55dac3808d4a31f271ee8f59a8076d7ea43c1feccb6f4581904667a6  innernet-server.initd
3c3b5c9fc5a72a288eff9dcf58fe535a40b99c419b5f25938ca689049caac9f93ba1d664d51f0dde8ee7e4578fc6eff68741f7ab6b540d471c26bf0cfd064a90  innernet-server.confd
e83ef3a3920f7598ffccb7f98ef083eb0f08b1c8ebd748cbe2287988d880321dadd0a94883e48915d68e35f1b57606d6bf90e9e56aa20c30419ec2dafce86377  unbundle-sqlite.patch
"
